package com.snow.common.controller;

import cn.afterturn.easypoi.excel.ExcelXorHtmlUtil;
import cn.afterturn.easypoi.excel.entity.ExcelToHtmlParams;
import com.snow.common.annotation.Common;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;

/**
 * All rights Reserved, Designed By www.cusc.com
 *
 * @author yanke
 * @Title: ExcelController
 * @Package com.snow.common.controller
 * @Description:类描述
 * @Email yanke@cu-sc.com
 * @version: v1.0.0
 * @date: 2021/7/1/0001 11:21
 * @Copyright: 2021  www.faw.com.cn Inc. All rights reserved. <br/>
 * Modification History:<br/>
 * Date         Author          Version            Description<br/>
 * *---------------------------------------------------------*<br/>
 * 2021/7/1/0001     Administrator           v1.0.0               修改原因<br/>
 * @since JDK 1.8
 */
@Slf4j
@RestController
@RequestMapping("/excel")
@Common
public class ExcelController {

    @GetMapping("/excelToHtml")
    public void toHtmlOf07Base(HttpServletResponse response) throws IOException, InvalidFormatException {
        File file = new File("D:/testOne.xlsx");
        ExcelToHtmlParams params = new ExcelToHtmlParams(WorkbookFactory.create(file));
        response.getOutputStream().write(ExcelXorHtmlUtil.excelToHtml(params).getBytes("utf-8"));
        response.setHeader(HttpHeaders.CONTENT_TYPE, "text/html;charset=utf-8");
    }
}
